package com.example.firstfive;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {
     private static final String TAG="Rate";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //接受传来的汇率
        Intent intent =getIntent();//获取传输页面数据

        float dollar2= intent.getFloatExtra("dollar_key",0.0f);
        float euro2= intent.getFloatExtra("euro_key",0.0f);
        float won2= intent.getFloatExtra("won_key",0.0f);
        Log.i(TAG,"onCreat: dollar2="+dollar2);
        Log.i(TAG,"onCreat: euro2="+euro2);
        Log.i(TAG,"onCreat: won2="+won2);
        //显示汇率
        EditText ed1 =(EditText) findViewById(R.id.ed1);
        EditText ed2 =(EditText) findViewById(R.id.ed2);
        EditText ed3 =(EditText) findViewById(R.id.ed3);
        ed1.setText(String.valueOf(dollar2));
        ed2.setText(String.valueOf(euro2));
        ed3.setText(String.valueOf(won2));
    }
    //保存修改后的数据
    public void save(View btn){
        //修改汇率
        Log.i(TAG, "click: 编辑汇率");
        //获取新的值

       EditText e1 =findViewById(R.id.ed1);
        String s1= e1.getText().toString();

        EditText e2 =findViewById(R.id.ed2);
        String s2= e2.getText().toString();
        EditText e3 =findViewById(R.id.ed3);
        String s3= e3.getText().toString();

        float dollarRate=Float.parseFloat(s1);
        float euroRate=Float.parseFloat(s2);
        float wonRate=Float.parseFloat(s3);

        //保存到bundle或者extra
        Log.i(TAG, "click: 成功封装");
        Intent  intent =getIntent();
        Bundle  bdl =new Bundle();
        bdl.putFloat("dollar_key1",dollarRate);
        bdl.putFloat("euro_key1",euroRate);
        bdl.putFloat("won_key1",wonRate);
        intent.putExtras(bdl);
        setResult(2,intent);//响应代码

        finish();
        Log.i(TAG, "click: 成功返回");
       // Intent intent = new Intent(this,MainActivity.class);
       // intent.putExtra("dollar_key1",dollarRate);
        //intent.putExtra("euro_key1",euroRate );
        //intent.putExtra("won_key1",wonRate );

        //Log.i(TAG,"open:dollar="+dollarRate);
        //Log.i(TAG,"open:euro="+euroRate);
        //Log.i(TAG,"open:won="+wonRate);
        //startActivity(intent);
}
}